package com.goodsClass.android.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;

import com.goodsClass.model.GoodsClassVO;

public class GoodsClassJSONHandler 
{
	public JSONArray toJSONArray ( List<GoodsClassVO> goodClassList, Map<String,Object> rsmd )
	{
		List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		int count = (int)rsmd.get( "columnCount" );
		String[] colName = (String[])rsmd.get( "columnName" );
		
		
		for ( GoodsClassVO goodClass : goodClassList )
		{
			HashMap<String, Object> map = new HashMap<>();
//			map.put( "GoodsClassNo", goodClass.getGoodsClassNo() );
//			map.put( "GoodsName", goodClass.getGoodsName() );
//			map.put( "GoodsOriginPlace", goodClass.getGoodsOriginPlace() );
//			map.put( "GoodsQuality", goodClass.getGoodsQuality() );
			for ( int i = 1; i <= count; i++ )
    		{
    			switch( colName[ i - 1 ] )
				{
				case  "GOODSCATAGORY" : map.put( colName[ i - 1 ], goodClass.getGoodsCatagory() );
					break;
				case "GOODSCLASSNO" : map.put( colName[ i - 1 ], goodClass.getGoodsClassNo() );
					break;
				case "GOODSTYPE" : map.put( colName[ i - 1 ], goodClass.getGoodsType() );
					break;
				case "GOODSSTYLE" : map.put( colName[ i - 1 ], goodClass.getGoodsStyle() );
					break;
				case "GOODSQUALITY" : map.put( colName[ i - 1 ], goodClass.getGoodsQuality() );
					break;
				case "GOODSORIGINPLACE" : map.put( colName[ i - 1 ], goodClass.getGoodsQuality() );
					break;
				case "GOODSNAME" : map.put( colName[ i - 1 ], goodClass.getGoodsName() );
					break;
				default: System.out.println( "no such column name!" );
				}//end switch
    		}//end for
			list.add( map );
		}
		JSONArray newJsonArray = new JSONArray( list );
		return newJsonArray;
	}
}
